<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>base64绀轰緥</title>
<script type="text/javascript" src="../ueditor/lib/third-party/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function ImgToBase64(file, maxLen, callBack) {
	debugger;
    var img = new Image();

    var reader = new FileReader();//璇诲彇瀹㈡埛绔笂鐨勬枃浠�
    reader.onload = function () {
        var url = reader.result;//璇诲彇鍒扮殑鏂囦欢鍐呭.杩欎釜灞炴�у彧鍦ㄨ鍙栨搷浣滃畬鎴愪箣鍚庢墠鏈夋晥,骞朵笖鏁版嵁鐨勬牸寮忓彇鍐充簬璇诲彇鎿嶄綔鏄敱鍝釜鏂规硶鍙戣捣鐨�.鎵�浠ュ繀椤讳娇鐢╮eader.onload锛�
        img.src = url;//reader璇诲彇鐨勬枃浠跺唴瀹规槸base64,鍒╃敤杩欎釜url灏辫兘瀹炵幇涓婁紶鍓嶉瑙堝浘鐗�
    };
    img.onload = function () {
        //鐢熸垚姣斾緥
        var width = img.width, height = img.height;
        //璁＄畻缂╂斁姣斾緥
        var rate = 1;
        if (width >= height) {
            if (width > maxLen) {
                rate = maxLen / width;
            }
        } else {
            if (height > maxLen) {
                rate = maxLen / height;
            }
        };
        img.width = width * rate;
        img.height = height * rate;
        //鐢熸垚canvas
        var canvas = document.createElement("canvas");
        var ctx = canvas.getContext("2d");
        canvas.width = img.width;
        canvas.height = img.height;
        ctx.drawImage(img, 0, 0, img.width, img.height);
        var base64 = canvas.toDataURL('image/jpeg', 0.9);
        callBack(base64);
    };
    reader.readAsDataURL(file);
}

	function getObjectURL(file) {
		debugger;
		var url = null;
		if (window.createObjectURL != null) { // basic
			url = window.createObjectURL(file);
		} else if (window.webkitURL != null) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		} else if (window.URL != null) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		}
		//createImageBitmap
		return url;
	}

	$(function() {
		var file = "file:///C:/Users/spc-00d/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg";
		/* ImgToBase64 (file, 720, function(data){
			$("#image").attr("src", data);
		}); */
		//$("#image").attr("src", getObjectURL(file));
		/* $.ajax({
			url:file,
			type:"jsonp",
			success:function(content){
				console.log(content);
			}
		}); */
		/* $.get(file).success(function(content){
			console.log(content);
		}); */
		
		/*  var reader = new FileReader();
		 reader.readAsText(file);
		reader.onload = function(){
			console.log(this.result);
		}; */
		//$("#uploadImg").attr("src", file);
		
		//$("#submitImg").click();
		/* $.ajax({
			url:"../FileUpload",
			type:"post",
			data: new FormData($("#upoladForm")),
			success : function(){
				
			}
		}); */
	/* 	function mySubmit(){
			alert(1);
			
			return false;
		} */
		$("#submit").on("click", function(){
			var formData = new FormData();
			//formData.append("file", $("#uploadForm"));
			var filedata = document.getElementById("uploadImg").files[0];
			console.log(filedata);
			formData.append("file", filedata);
			$.ajax({
				url:"../FileUpload",
				type:"post",
				data:formData,
				async:false,
				processData:false,
				//contentType:"multipart/form-data",
				contentType : false,
				success:function(){
					//debugger;
					//alert(1);
					
				}
			});
			return false;
		});
		
		
	});
</script>
</head>
<body>
	<!-- <img id="image" alt="" src="" style="height:638px; width:553px"> -->
	<div >
		<form id="uploadForm" method="post" enctype="multipart/form-data">
			<input id="uploadImg" name="uploadImg" type="file">
			<!-- <input type="submit" value="鎻愪氦"> -->
			<button id="submit">submit</button>
		</form>
	</div>
	<!-- <iframe src="file:///C:/Users/spc-00d/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg"></iframe> -->
</body>
</html>